#include "epoll_server.hpp"
#include "listener.hpp"
#include "connection.hpp"
#include <string>
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    ENABLE_CONSOLE_LOG();
    uint16_t local_port = std::stoi(argv[1]);
    listener tcp_listener(local_port);
    auto conn = std::make_shared<connection>(tcp_listener.fd());
    conn->set_call_back(
        [&](){
            tcp_listener.accepter();
        }, 
        nullptr,
        nullptr);
    conn->set_events(EPOLLIN|EPOLLET);

    epoll_server epoll_svr;
    epoll_svr.init();
    epoll_svr.insert_connection(*conn);
    epoll_svr.loop();

    return 0;
}